﻿using Microsoft.AspNetCore.Mvc;
using MinimalistFoodStreet.BackEnd.Infrastructure.Attributes;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Request.Functions;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Request.Tables;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Response;
using MinimalistFoodStreet.BackEnd.Server.IServer.Tables;

namespace MinimalistFoodStreet.BackEnd.Api.Api.Controllers.Tables
{
    [CheckLogin(new CheckLoginRoles[] {CheckLoginRoles.business})]
    public class ChartsController:BaseController
    {
        private readonly IChartsServer _chartsServer;

        public ChartsController(IChartsServer chartsServer)
        {
            _chartsServer = chartsServer;
        }
        /// <summary>
        /// 添加到购物车
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add(RequestCreateChartsDto dto) {
            return Send(await _chartsServer.Add(dto,_business.BId));
        }
        /// <summary>
        /// 从删除商品
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete(RequestIdChartsDto dto) {
            return Send(await _chartsServer.Delete(dto));
        }
        /// <summary>
        /// 增加商品数量（每次加一）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async  Task<IActionResult> Increase(RequestIdChartsDto dto) {
            return Send(await _chartsServer.Increase(dto));
        }
        /// <summary>
        /// 减少商品数量（每次减一）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Decrease(RequestIdChartsDto dto) {
            return Send(await _chartsServer.Decrease(dto));
        }
        /// <summary>
        /// 设置商品数量
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> SetChartGoodCount(RequestSetChartGoodCount dto) {
            return Send(await _chartsServer.SetChartGoodCount(dto));
        }
        /// <summary>
        /// 获取购物车列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetCartList()
        {
            return Send(await _chartsServer.GetCartList(_business.BId));
        }
    }
}
